package photogcalc.calculators;

import java.util.Hashtable;
import java.util.Vector;
import photogcalc.BaseModel;
import photogcalc.common.FrameSize;
import photogcalc.common.ISOValue;
import photogcalc.util.Settings;

/** A base model for the other calculetor models. Contains a common data,
 *  methods etc.
 *
 * @author aokkonen
 */
public class CalculatorModel extends BaseModel {
    /** sensor / film dimensions */
    private Hashtable frameSizes = new Hashtable();

    /** camera formats */
    private Hashtable formats = new Hashtable();

    /** iso values */
    private Vector ISOs = new Vector();

    /** one-third-stop f-number scale */
    private Vector fstops = new Vector();

    /** focal lengths */
    private Vector flengths = new Vector();

    public CalculatorModel(Settings settings) {
        setSettings(settings);

        // Initialize camera formats
        
        formats.put("645", new Integer(1));
        formats.put("Leica S-System", new Integer(2));
        formats.put("35mm", new Integer(3));
        formats.put("APS-H (1,3x)", new Integer(4));
        formats.put("APS-C (1,5x)", new Integer(5));
        formats.put("APS-C (1,6x)", new Integer(6));
        formats.put("APS-C (1,7x)", new Integer(7));
        formats.put("Four Thirds", new Integer(8));
        formats.put("2/3\"", new Integer(9));
        formats.put("1/1.6\" (Fujifilm F60FD)", new Integer(10));
        formats.put("1/1.8\"", new Integer(11));
        formats.put("1/2.5\" (K-M Z6)", new Integer(12));

        // Initialize the frame sizes and the CoCs.
        // http://johndudak.com/photographers/dof.php
        // Use a standard CoC value.
        frameSizes.put("645", new FrameSize(56, 41.5, 0.053));
        frameSizes.put("Leica S-System", new FrameSize(45, 30, 0.038));
        frameSizes.put("35mm", new FrameSize(36, 24, 0.030));
        frameSizes.put("APS-H (1,3x)", new FrameSize(28.7, 19.1, 0.024));
        frameSizes.put("APS-C (1,5x)", new FrameSize(23.6, 15.7, 0.020));
        frameSizes.put("APS-C (1,6x)", new FrameSize(22.2, 14.8, 0.019));
        frameSizes.put("APS-C (1,7x)", new FrameSize(20.7, 13.8, 0.018));
        frameSizes.put("Four Thirds", new FrameSize(17.3, 13, 0.017));
        frameSizes.put("2/3\"", new FrameSize(8.8, 6.6, 0.008));
        frameSizes.put("1/1.6\" (Fujifilm F60FD)", new FrameSize(7.78, 5.83, 0.007));
        frameSizes.put("1/1.8\"", new FrameSize(7.18, 5.32, 0.007));
        frameSizes.put("1/2.5\" (K-M Z6)", new FrameSize(5.76, 4.29, 0.005));

        // ISO values
        ISOs.addElement(new ISOValue(50, 18));
        ISOs.addElement(new ISOValue(64, 19));
        ISOs.addElement(new ISOValue(80, 20));
        ISOs.addElement(new ISOValue(100, 21)); // full stop
        ISOs.addElement(new ISOValue(125, 22));
        ISOs.addElement(new ISOValue(160, 23));
        ISOs.addElement(new ISOValue(200, 24)); // full stop
        ISOs.addElement(new ISOValue(250, 25));
        ISOs.addElement(new ISOValue(320, 26));
        ISOs.addElement(new ISOValue(400, 27)); // full stop
        ISOs.addElement(new ISOValue(500, 28));
        ISOs.addElement(new ISOValue(640, 29));
        ISOs.addElement(new ISOValue(800, 30)); // full stop
        ISOs.addElement(new ISOValue(1000, 31));
        ISOs.addElement(new ISOValue(1250, 32));
        ISOs.addElement(new ISOValue(1600, 33)); // full stop
        ISOs.addElement(new ISOValue(2000, 34));
        ISOs.addElement(new ISOValue(2500, 35));
        ISOs.addElement(new ISOValue(3200, 36)); // full stop
        ISOs.addElement(new ISOValue(4000, 37));
        ISOs.addElement(new ISOValue(5000, 38));
        ISOs.addElement(new ISOValue(6400, 39)); // full stop
        ISOs.addElement(new ISOValue(12800, 42)); // full stop
        
        // f-stops
        fstops.addElement(new Double(0.95)); // full stop
        fstops.addElement(new Double(1.0)); // full stop
        fstops.addElement(new Double(1.1));
        fstops.addElement(new Double(1.2));
        fstops.addElement(new Double(1.4)); // full stop
        fstops.addElement(new Double(1.6));
        fstops.addElement(new Double(1.8));
        fstops.addElement(new Double(2.0)); // full stop
        fstops.addElement(new Double(2.2));
        fstops.addElement(new Double(2.5));
        fstops.addElement(new Double(2.8)); // full stop
        fstops.addElement(new Double(3.2));
        fstops.addElement(new Double(3.5));
        fstops.addElement(new Double(4.0)); // full stop
        fstops.addElement(new Double(4.5));
        fstops.addElement(new Double(5.0));
        fstops.addElement(new Double(5.6)); // full stop
        fstops.addElement(new Double(6.3));
        fstops.addElement(new Double(7.1));
        fstops.addElement(new Double(8.0)); // full stop
        fstops.addElement(new Double(9.0));
        fstops.addElement(new Double(10));
        fstops.addElement(new Double(11)); // full stop
        fstops.addElement(new Double(13));
        fstops.addElement(new Double(14));
        fstops.addElement(new Double(16)); // full stop
        fstops.addElement(new Double(18));
        fstops.addElement(new Double(20));
        fstops.addElement(new Double(22)); // full stop
        fstops.addElement(new Double(32)); // full stop
        fstops.addElement(new Double(45)); // full stop
        fstops.addElement(new Double(64)); // full stop

        flengths.addElement(new Double(8));
        flengths.addElement(new Double(9));
        flengths.addElement(new Double(10));
        flengths.addElement(new Double(11));
        flengths.addElement(new Double(12));
        flengths.addElement(new Double(14));
        flengths.addElement(new Double(15));
        flengths.addElement(new Double(16));
        flengths.addElement(new Double(17));
        flengths.addElement(new Double(17.5));
        flengths.addElement(new Double(18));
        flengths.addElement(new Double(20));
        flengths.addElement(new Double(21));
        flengths.addElement(new Double(24));
        flengths.addElement(new Double(25));
        flengths.addElement(new Double(28));
        flengths.addElement(new Double(30));
        flengths.addElement(new Double(35));
        flengths.addElement(new Double(40));
        flengths.addElement(new Double(42));
        flengths.addElement(new Double(45));
        flengths.addElement(new Double(50));
        flengths.addElement(new Double(54));
        flengths.addElement(new Double(55));
        flengths.addElement(new Double(60));
        flengths.addElement(new Double(70));
        flengths.addElement(new Double(85));
        flengths.addElement(new Double(90));
        flengths.addElement(new Double(100));
        flengths.addElement(new Double(105));
        flengths.addElement(new Double(135));
        flengths.addElement(new Double(150));
        flengths.addElement(new Double(200));
        flengths.addElement(new Double(210));
        flengths.addElement(new Double(300));
        flengths.addElement(new Double(400));
        flengths.addElement(new Double(500));
        flengths.addElement(new Double(600));
    }

    public Hashtable getCameraFormats() {
        return formats;
    }

    public Hashtable getFrameSizes() {
        return frameSizes;
    }

    public Vector getISOs() {
        return ISOs;
    }

    public Vector getFstops() {
        return fstops;
    }

    public Vector getFlengths() {
        return flengths;
    }
}
